library(readr)
library(tidyr)
library(stringr)
library(data.table)
library(tidyverse)
library(reshape2)



# load in data from the two waves
load("political.Rda")
load("covid.Rda")

# merge them
combined_data <- rbind(to_merge, to_mergeCOVID)

# construct FB newsfeed digital literacy variable
#     if people said dont know on first response, use their second response
combined_data[!is.na(combined_data$FbDec_1),]$FbDec <- combined_data[!is.na(combined_data$FbDec_1),]$FbDec_1
combined_data$diglit2 <- combined_data$FbDec==4



### 
# Accuracy discernment

# each variable separately
acc_model_diglit <- lm(scale(acc_discernment)~(scale(diglit)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(acc_model_diglit)
acc_model_diglit2 <- lm(scale(acc_discernment)~(scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(acc_model_diglit2)
acc_model_crt <- lm(scale(acc_discernment)~(scale(crt)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(acc_model_crt)
acc_model_newsknow <- lm(scale(acc_discernment)~(scale(newsknow)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(acc_model_newsknow)

# all together
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C)*scale(political),data=combined_data)
summary(acc_model)
#
# decomposing to look at interactions
#
# dem
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C<4)   ,])
summary(acc_model)
# rep 
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C>3)   ,])
summary(acc_model)
# covid
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==0)  ,])
summary(acc_model)
# politics
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==1)  ,])
summary(acc_model)s
#
# dem covid
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==0)  ,])
summary(acc_model)
# dem politics
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==1)  ,])
summary(acc_model)
# rep covid
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==0)  ,])
summary(acc_model)
# rep politics
acc_model <- lm(scale(acc_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==1)  ,])
summary(acc_model)







### 
# Sharing  discernment

# each variable separately
sharing_model_diglit <- lm(scale(sharing_discernment)~(scale(diglit)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing_model_diglit)
sharing_model_diglit2 <- lm(scale(sharing_discernment)~(scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing_model_diglit2)
sharing_model_crt <- lm(scale(sharing_discernment)~(scale(crt)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing_model_crt)
sharing_model_newsknow <- lm(scale(sharing_discernment)~(scale(newsknow)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing_model_newsknow)

# All together
sharing_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C)*scale(political),data=combined_data)
summary(sharing_model)
#
# decomposing to look at interactions
# dem
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C<4)   ,])
summary(s_model)
# rep 
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C>3)   ,])
summary(s_model)
# covid
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==0)  ,])
summary(s_model)
# politics
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==1)  ,])
summary(s_model)
#
#
# dem covid
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==0)  ,])
summary(s_model)
# dem politics
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==1)  ,])
summary(s_model)
# rep covid
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==0)  ,])
summary(s_model)
# rep politics
s_model <- lm(scale(sharing_discernment)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==1)  ,])
summary(s_model)



####
# Fraction of shared news that is true

# each variable separately
sharing2_model_diglit <- lm(scale(sharing_discernment2)~(scale(diglit)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing2_diglit)
sharing2_model_diglit2 <- lm(scale(sharing_discernment2)~(scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing2_diglit2)
sharing2_model_crt <- lm(scale(sharing_discernment2)~(scale(crt)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing2_model_crt)
sharing2_model_newsknow <- lm(scale(sharing_discernment2)~(scale(newsknow)+scale(college)+scale(age)+scale(female)+scale(white))+scale(DemRep_C)+scale(political),data=combined_data)
summary(sharing2_model_newsknow)

# all together
sharing2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C)*scale(political),data=combined_data)
summary(sharing2_model)
#
# decomposing to see interactions
# dem
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C<4)   ,])
summary(s2_model)
# rep 
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(political),data=combined_data[(combined_data$DemRep_C>3)   ,])
summary(s2_model)
# covid
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==0)  ,])
summary(s2_model)
# politics
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white))*scale(DemRep_C),data=combined_data[ (combined_data$political==1)  ,])
summary(s2_model)
#
#
# dem covid
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==0)  ,])
summary(s2_model)
# dem politics
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C<4) & (combined_data$political==1)  ,])
summary(s2_model)
# rep covid
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==0)  ,])
summary(s2_model)
# rep politics
s2_model <- lm(scale(sharing_discernment2)~(scale(crt)+scale(newsknow)+scale(diglit)+scale(diglit2)+scale(college)+scale(age)+scale(female)+scale(white)),data=combined_data[(combined_data$DemRep_C>3) & (combined_data$political==1)  ,])
summary(s2_model)

